﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using WebApplication1.Classes;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace WebApplication1
{
    public partial class details : System.Web.UI.Page
    {
        private string Сonn = @"Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=Test;
Integrated Security=True;Pooling=False";
        private List<Flat> flatList;
        private List<Contract> conList;
        private List<Client> clList;
        private Contract x;
        private Flat y;
        private Client z;
        private int num;


        protected void Page_Load(object sender, EventArgs e)
        {
            num = Convert.ToInt32(Session["con"].ToString());
            //DropDownList1.Items.Add(Label1.Text);
            Session.Remove("con"); 
            //DropDownList1.SelectedIndex = 0;
            SqlConnection connection = new SqlConnection(Сonn);
            connection.Open();
            try
            {
                flatList = new List<Flat>();
                conList = new List<Contract>();
                clList = new List<Client>();
//ищем номер сертификата собственности по номеру договора
                SqlCommand сommand2 = new SqlCommand("select * from Contract where Id='" + num + "'", connection);
                SqlDataReader reader = сommand2.ExecuteReader();
                while (reader.Read())
                {
                    conList.Add(new Contract(Convert.ToInt32(reader["Id"]), Convert.ToInt32(reader["IdFlat"]), Convert.ToInt32(reader["IdAgent"]), Convert.ToBoolean(reader["Fire"]), Convert.ToBoolean(reader["Water"]), Convert.ToBoolean(reader["Wear"]), Convert.ToBoolean(reader["Problem"]), Convert.ToBoolean(reader["Loot"]), Convert.ToDateTime(reader["Date"]), Convert.ToInt32(reader["Sum"])));
                }
                reader.Close();
                x = conList.First();  
//ищем данные о собственности c этим сертификатом
                SqlCommand сommand1 = new SqlCommand("select * from Flat where Certificate='" + x.IdFlat + "'", connection);
                SqlDataReader reader1 = сommand1.ExecuteReader();

                while (reader1.Read())
                {
                    flatList.Add(new Flat(Convert.ToInt32(reader1["Certificate"]), Convert.ToInt32(reader1["IdClient"]), Convert.ToString(reader1["Adress"]), Convert.ToBoolean(reader1["LostFloor"]), Convert.ToInt32(reader1["Rooms"]), Convert.ToDouble(reader1["Square"]), Convert.ToInt32(reader1["Year"]), Convert.ToInt32(reader1["Price"])));
                }
                reader1.Close();
                y = flatList.First();
//ищем данные о собственнике этой собственности
                SqlCommand сommand3 = new SqlCommand("select * from Client where Id='" + y.IdClient + "'", connection);
                SqlDataReader reader2 = сommand3.ExecuteReader();

                while (reader2.Read())
                {
                    clList.Add(new Client(Convert.ToInt32(reader2["Id"]), Convert.ToInt32(reader2["PassportSerial"]), Convert.ToString(reader2["Birth"]), Convert.ToInt32(reader2["PassportNumber"]), Convert.ToString(reader2["Name"]), Convert.ToString(reader2["Surname"]), Convert.ToInt32(reader2["Phone"]), Convert.ToString(reader2["Email"])));
                }

                reader2.Close();
                z = clList.First(); 
                Label3.Text = ("Имя клинета- "+z.Name);
                Label4.Text = ("Фамилия клиента- "+z.Surname);
                Label5.Text = ("Дата рождения клиента- "+z.Birth);
                Label6.Text = ("E-mail клиента- "+z.Email);
                Label7.Text = ("Адрес квартиры- "+y.Adress);
                Label8.Text = ("Площадь квартиры- "+Convert.ToString(y.Square));
                Label9.Text = ("Количество комнат- "+Convert.ToString(y.Rooms));
                Label10.Text = ("Рыночная стоимость- "+Convert.ToString(y.Price));
            }
            catch (SqlException ex)
            {
               
                
            }
            connection.Close();
           
        }
    }
}
